package main;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 * Window to Prompt user to search for a contact or contacts
 *  by last name, zip code, or email address
 *  
 *  @author Olga
 *
 */
public class SearchContactWindow extends JDialog {
    
    private static final String PAGETITLE = "Search";

    private JPanel mainPanel;
    private JComboBox options;
    private JButton searchButton;
    private JLabel searchLabel;
    private JTextField searchTextField;
    
    /**
     * Constructor. Lays out window, with combo box to select how to search
     * and textfield to give search keyword and button to execute search
     * @param controller the gui event handler
     */
    public SearchContactWindow(ActionListener controller) {
        
        this.setIconImage(Toolkit.getDefaultToolkit().getImage("res/icon.png"));
        
        mainPanel = new JPanel();
        
        //Label
        searchLabel = new JLabel("Search:");
        
        //Search Text Field
        searchTextField = new JTextField(10);
        
        //Search Filter
        String[] searchStrings = {"Last Name", "Email", "Zip Code"};
        options = new JComboBox(searchStrings);
        options.setSelectedIndex(2);
        options.addActionListener(controller);
        
        //Search Button
        searchButton = new JButton("Search");
        searchButton.setActionCommand("search_search");
        searchButton.addActionListener(controller);
        
        mainPanel.add(searchLabel);
        mainPanel.add(searchTextField);
        mainPanel.add(options);
        mainPanel.add(searchButton);
        this.getRootPane().setDefaultButton(searchButton);
        this.add(mainPanel);
        this.setTitle(Main.TITLE + ": " + PAGETITLE);
        pack();
        setResizable(false);
    }
    
    /**
     * @return user selected search filter
     */
    public String getSearchFilter() {
    	return (String) options.getSelectedItem();
    }
    
    /**
     * 
     * @return user inputed search keywords
     */
    public String getSearchKeywords() {
    	return searchTextField.getText();
    }

    
}
